package com.itheima.project.knowledge;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import com.itheima.project.*;

public class SubPageContentAdapter extends RecyclerView.Adapter<SubPageContentAdapter.SubPageHolder> {

    private List<KnowledgeSubPageEntity.DataBean.DatasBean> mList;
    private Context context;

    public SubPageContentAdapter(List<KnowledgeSubPageEntity.DataBean.DatasBean> mList, Context context) {
        this.mList = mList;
        this.context = context;
    }

    @NonNull
    @Override
    public SubPageHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.knowledge_subpage_content_item, parent, false);
        return new SubPageHolder(inflate) ;
    }

    @Override
    public void onBindViewHolder(@NonNull SubPageHolder holder, int position) {
        KnowledgeSubPageEntity.DataBean.DatasBean datasBean = mList.get(position);
        holder.tvAuthor.setText(datasBean.getAuthor());
        holder.tvChapterName.setText(datasBean.getChapterName());
        holder.tvTitle.setText(datasBean.getTitle());
        holder.tvNiceDate.setText(datasBean.getNiceDate());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public static class SubPageHolder extends RecyclerView.ViewHolder{
        TextView tvAuthor;
        TextView tvChapterName;
        TextView tvTitle;
        TextView tvNiceDate;
        public SubPageHolder(@NonNull View itemView) {
            super(itemView);
            tvAuthor = itemView.findViewById(R.id.tv_author_knowledge_subpage_content_item);
            tvChapterName = itemView.findViewById(R.id.tv_chapterName_knowledge_subpage_content_item);
            tvTitle = itemView.findViewById(R.id.tv_tittle_knowledge_subpage_content_item);
            tvNiceDate = itemView.findViewById(R.id.tv_niceData_knowledge_subpage_content_item);
        }
    }
}
